import TbColumn from "@/components/table/tbColumn";
import { formatPercentage, isNull } from "@/utils/service";

function formatDateToDay(dateStr) {
  const date = new Date(dateStr.dataDate);
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0');
  const day = String(date.getDate()).padStart(2, '0');

  return `${year}-${month}-${day}`;
}
/** 表格值保留两位小数且空值将以 '-' 字符替代*/
function percentageWithFixedDigits2(row, column, cellValue, index) {
  if(typeof(cellValue) === 'number'){
    return cellValue.toFixed(2);
  }else if (typeof(cellValue) === 'string'){
    return cellValue ? cellValue : '-'
  }else {
    return '-'
  }
}
/** 将表格值转为百分比*/
function valueToPercentage(row, column, cellValue, index) {
  return formatPercentage(cellValue);
}
function valueToCharacter(row, column, cellValue, index){
  return !isNull(cellValue) ? cellValue : '-'
}
export const COLUMNS = [
  new TbColumn("店铺名称", "storeName", {
    width: 200, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("数据日期", "dataDate", {
    width: 120, sortable: true, align: "center", formatter: formatDateToDay }),
  new TbColumn("店铺总销售额", "totalStoreSales", {
    width: 150, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("刷单金额", "brushOrdersAmount", {
    width: 120, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("真实额1","realAmountOne", {
    width: 150, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("退款金额","refundAmount", {
    width: 120, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("真实额2","realAmountTwo", {
    width: 150, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("真实订单数","realOrderNum", {
    width: 120, sortable: true, align: "center", formatter: valueToCharacter }),
  new TbColumn("客单价","customerUnitPrice", {
    width: 120, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("订单总数","totalOrders", {
    width: 120, sortable: true, align: "center", formatter: valueToCharacter }),
  new TbColumn("补单订单数","supplementaryOrders", {
    width: 120, sortable: true, align: "center", formatter: valueToCharacter }),
  new TbColumn("免费送","freeDelivery", {
    width: 100, sortable: true, align: "center", formatter: valueToCharacter }),
  new TbColumn("访客","visitor", {
    width: 100, sortable: true, align: "center", formatter: valueToCharacter }),
  new TbColumn("转化率","conversionRate", {
    width: 100, sortable: true, align: "center" }),
  new TbColumn("补单佣金加快递","supplementaryCommissionExpress", {
    width: 150, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("多多搜索","duoduoSearch", {
    width: 120, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("搜索成交","searchDeal", {
    width: 120, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("多多场景","duoduoScene", {
    width: 120, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("场景成交","sceneDeal", {
    width: 120, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("明星店铺推广","starStorePromotion", {
    width: 150, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("明星店铺成交","starStoreDeal", {
    width: 150, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("全站推广","websitePromotion", {
    width: 120, sortable: true, align: "center",  formatter: percentageWithFixedDigits2 }),
  new TbColumn("全站推广成交","websitePromotionDeal", {
    width: 150, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("推广ROI","promoteRoi", {
    width: 120, sortable: true, align: "center", formatter: percentageWithFixedDigits2 }),
  new TbColumn("广告费占比","proportionOfAdvertisingExpenses", {
    width: 120, sortable: true, align: "center", formatter: valueToPercentage }),
  new TbColumn("领航员综合分行业排名","comprehensiveScoreIndustryRanking", {
    width: 200, sortable: true, align: "center" }),
  new TbColumn("求助率(近30天)","helpRate", {
    width: 150, sortable: true, align: "center" }),
  new TbColumn("总订单数(近30天)","totalOrdersLastThirtyDays", {
    width: 200, sortable: true, align: "center", formatter: valueToCharacter }),
  new TbColumn("刷单订单数(近30天)","supplementaryOrdersLastThirtyDays", {
    width: 200, sortable: true, align: "center", formatter: valueToCharacter }),
  new TbColumn("免费送订单数(近30天)","freeDeliveryLastThirtyDays", {
    width: 200, sortable: true, align: "center", formatter: valueToCharacter }),
  new TbColumn("创建时间", "createTime", {
    width: 180, sortable: true, align: "center" }),
  new TbColumn("修改时间", "updateTime", {
    width: 180, sortable: true, align: "center" }),
];